package org.vectrics.recruiter.struts.admin.person;

import javax.servlet.jsp.JspException;

import org.vectrics.cv.Language;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;

/**
 * @author pgoette
 * Clase Action encargada de guardar los Language
 */
public class SaveLanguageAction extends VectricsStrutsAction {

	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {
		
		String forward = "success";
		LanguageForm form = (LanguageForm) actionData.getForm();
		Language language = null;		
		
		if (actionData.wasButtonPressed("cancel")) {
			return forward;
		}
		
		if ((form.getId() == null)||(form.getId().trim().equals(""))) {
			language = new Language();
		} else {
			language = RecruitServiceLocator.getPersonService().findLanguageById(new Long(form.getId()));
		}
		
		language.setName(form.getName());
		RecruitServiceLocator.getPersonService().saveLanguage(language);
		
		return forward;
	}

}
